Skip to content

Conversation

@gregfromstl
Copy link
Contributor

@gregfromstl gregfromstl commented Jan 20, 2025

PR-Codex overview

This PR introduces changes to make the chain parameter optional for smart wallet functionalities, enhancing flexibility in smart account integration. It also updates related tests and documentation to reflect these changes.

Detailed summary

  • Updated ConnectButton to make chain optional in smartWalletOptions.
  • Modified type definitions for SmartWalletOptions and SmartAccountOptions to allow optional chain.
  • Adjusted logic in several functions to handle cases where chain is undefined.
  • Updated tests to validate behavior with default chain settings.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@gregfromstl gregfromstl requested review from a team as code owners January 20, 2025 03:01
@changeset-bot
Copy link

changeset-bot bot commented Jan 20, 2025

🦋 Changeset detected

Latest commit: 0783395

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
thirdweb Minor
@thirdweb-dev/wagmi-adapter Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Jan 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 20, 2025 10:05pm
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 20, 2025 10:05pm
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 20, 2025 10:05pm
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 20, 2025 10:05pm

@linear
Copy link

linear bot commented Jan 20, 2025

@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels Jan 20, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Jan 20, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 20, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 46.66 KB (0%) 934 ms (0%) 3.9 s (-7.16% 🔽) 4.8 s
thirdweb (cjs) 116.69 KB (-0.13% 🔽) 2.4 s (-0.13% 🔽) 6.2 s (-18.39% 🔽) 8.5 s
thirdweb (minimal + tree-shaking) 5.59 KB (0%) 112 ms (0%) 629 ms (+117.82% 🔺) 741 ms
thirdweb/chains (tree-shaking) 506 B (0%) 10 ms (0%) 55 ms (-25% 🔽) 65 ms
thirdweb/react (minimal + tree-shaking) 19.26 KB (+0.14% 🔺) 386 ms (+0.14% 🔺) 960 ms (+44.25% 🔺) 1.4 s

const options = creationOptions;
const chain = connectChain ?? options.chain;
// Fallback to mainnet if no chain is provided (we only need this for pre-deploy signatures since transactions and deployments must define their own chain)
const chain = connectChain ?? options.chain ?? getCachedChain(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One issue I see is that below this we get the factory and account contracts based on this chain variable.

It works with our default factory because it's deterministic (though need to double check it's on mainnet) but might error if you pass another factory address and no chain.

Also would double check we don't use this chain car for other assumptions in this connect flow

@gregfromstl gregfromstl force-pushed the greg/tool-3141-sdk-make-smart-account-chain-id-optional branch from 7357730 to cbdb7cd Compare January 20, 2025 21:36
Comment on lines +132 to +137
if (
typeof createOptions.factoryAddress === "undefined" &&
typeof createOptions.chain !== "undefined"
) {
throw new Error("You must provide a chain if factory address is specified");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition appears to be checking the wrong logic - it currently throws when factoryAddress is undefined but chain is defined. The intended validation is to require chain when factoryAddress is provided. The condition should be:

if (typeof createOptions.factoryAddress !== 'undefined' && typeof createOptions.chain === 'undefined')

This ensures that a chain is specified whenever a custom factory address is used.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +132 to +137
if (
typeof createOptions.factoryAddress === "undefined" &&
typeof createOptions.chain !== "undefined"
) {
throw new Error("You must provide a chain if factory address is specified");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation logic appears to be inverted. The current check allows a chain to be specified without a factoryAddress, but throws when neither is provided. To enforce that a chain must be provided when factoryAddress is specified, the condition should be:

if (typeof createOptions.factoryAddress !== 'undefined' && typeof createOptions.chain === 'undefined')

This ensures that smart wallets with custom factories have the required chain configuration.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

@gregfromstl
Copy link
Contributor Author

Closing as this breaks zk chains

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages SDK Involves changes to the thirdweb SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants